const streams = {
    sccrenStream: null, // 屏幕视频流
    sysAudioStream: null, // 系统音频流
    micorStream: null, // 麦克风音频流
    cameraStream: null // 摄像头视频流
}


//录制设置
const menu = document.querySelector('.menu')
const minute = document.querySelector('.minute')
menu.addEventListener('click', (event)=> {
    // 移除所有class属性
    menu.querySelector('.menu-ishow').classList.remove('menu-ishow')
    //添加class属性
    event.target.classList.add('menu-ishow')
    //获取目标元素的data
    const dataId = event.target.dataset.id
    const minuteChilds = Array.from(minute.children)
    // 找到minute子元素的data-for和dataId相等的元素
    minuteChilds.forEach(element => {
        // data-for不等于data-id的元素移除属性minute-ishow
        if(element.dataset.for === dataId) {
            return element.classList.remove('minute-ishow')
        }
        // 添加class属性
        element.classList.add('minute-ishow')
    });
})


// 录制器
class CreateRecorder {
    constructor(stream, type, mark) {
        this.recorder = new MediaRecorder(stream)
        this.chunks = []
        this.recorder.ondataavailable = (e) => {
            this.chunks.push(e.data)
        }
        this.recorder.onstop = () => {
            const blob = new Blob(this.chunks, type)
            window.ffmpegAPI.saveTempBlob(blob, mark)
        }
    }
    start() {
        this.recorder.start()
    }
    stop() {
        this.recorder.stop()
    }
    pause() {
        this.recorder.pause()
    }
    resume() {
        this.recorder.resume()
    }
}
// 录制器管理
class RecorderManager {
    constructor() {
        this.recorders = new Map()
    }
    addRecorder(recKey, recVal) {
        this.recorders.set(recKey, recVal)
    }
    removeRecorder(recKey) {
        this.recorders.delete(recKey)
    }
    start() {
        // 开始录制
        this.recorders.forEach(recorder => {
            recorder.start()
        })
    }
    stop() {
        // 停止录制
        this.recorders.forEach(recorder => {
            recorder.stop()
        })
    }
    pause() {
        // 暂停录制
        this.recorders.forEach(recorder => {
            recorder.pause()
        })
    }
    resume() {
        // 继续录制
        this.recorders.forEach(recorder => {
            recorder.resume()
        })
    }
    // 是否有录制器
    isRecorder() {
        return this.recorders.size > 0
    }
}